<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" label-width="100px">
            <span class="seachTiele">时间选择：</span>
            <el-radio-group v-model="tableFrom.date" type="button" class="mr20" size="small"
              @change="selectChange(tableFrom.date)" clearable>
              <el-radio-button v-for="(item,i) in fromList.fromTxt" :key="i" :label="item.val">{{ item.text }}
              </el-radio-button>
            </el-radio-group>
            <el-date-picker v-model="timeVal" value-format="yyyy/MM/dd" format="yyyy/MM/dd" size="small"
              type="daterange" placement="bottom-end" placeholder="自定义时间" style="width: 250px;" @change="onchangeTime"
              clearable />
            <div class="mt20">
              <span class="seachTiele">商品信息：</span>
              <el-input v-model="tableFrom.keyword" @keyup.enter.native="getList(1)" placeholder="请输入商品ID或者商品信息"
                class="selWidth mr20" clearable />
              <span class="seachTiele">用户名称：</span>
              <el-input v-model="tableFrom.nickname" @keyup.enter.native="getList(1)" placeholder="请输入用户名称"
                class="selWidth mr20" />
              <el-button size="small" type="primary" icon="el-icon-search" @click="getList(1)">搜索</el-button>
            </div>
          </el-form>
        </div>
      </div>
      <el-table v-loading="listLoading" :data="tableData.data" style="width: 100%" size="mini"
        @rowclick.stop="closeEdit" :row-class-name="tableRowClassName">
        <el-table-column prop="StoreProduct.product_id" label="商品ID" min-width="50" />
        <el-table-column label="商品信息" min-width="180">
          <template slot-scope="scope">
            <div class="tabBox acea-row row-middle">
              <div class="demo-image__preview">
                <el-image :src="scope.row.StoreProduct.image" :preview-src-list="[scope.row.StoreProduct.image]" />
              </div>
              <span class="tabBox_tit">{{ scope.row.StoreProduct.store_name }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="用户信息" min-width="180">
          <template slot-scope="scope">
            <div class="tabBox acea-row row-middle">
              <div class="demo-image__preview">
                <el-image :src="scope.row.User.avatar" :preview-src-list="[scope.row.User.avatar]" />
              </div>
              <span class="tabBox_tit">{{ scope.row.User.nickname }}</span>
            </div>
          </template>
        </el-table-column>

        <el-table-column prop="content" label="评价内容" min-width="150">
          <template slot-scope="scope">
            <div class="mb5 content_font">{{ scope.row.content }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="pic" label="图片" min-width="150">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image v-for="(item,index) in scope.row.pic" :key="index" :src="item" class="mr5"
                :preview-src-list="[item]" />
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" min-width="150">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 0" type="info">待审核</el-tag>
            <el-tag v-if="scope.row.status == 1" type="success">审核通过</el-tag>
            <el-tag v-if="scope.row.status == 2" type="warning">
              审核失败
              <p>原因：{{scope.row.reason}}</p>
              </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="反馈时间" min-width="100" />

        <el-table-column label="操作" min-width="80" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="small" v-if="scope.row.status==0" @click="handleReply(scope.row.id)">审核</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination :page-sizes="[20, 40, 60, 80]" :page-size="tableFrom.limit" :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper" :total="tableData.total" @size-change="handleSizeChange"
          @current-change="pageChange" />
      </div>
      <el-dialog title="审核" :visible.sync="editDialogVisible" width="60%">

        <el-form :model="editData" status-icon ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="状态" prop="name">
            <el-select v-model="editData.status" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="原因" prop="reason" v-if="editData.status == 2">
            <el-input v-model="editData.reason"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="save">确 定</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>

</template>

<script>
  // +----------------------------------------------------------------------
  // | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
  // +----------------------------------------------------------------------
  // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  // +----------------------------------------------------------------------
  // | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
  // +----------------------------------------------------------------------
  // | Author: CRMEB Team <admin@crmeb.com>
  // +----------------------------------------------------------------------
  import {
    highPriceLstApi,
    highPriceCheckApi
  } from '@/api/product'
  export default {
    data() {
      return {
        tableData: {
          data: [],
          total: 0
        },
        listLoading: true,
        tableFrom: {
          nickname: '',
          keyword: '',
          date: '',
          page: 1,
          limit: 20
        },
        timeVal: [],
        fromList: {
          title: '选择时间',
          custom: true,
          fromTxt: [{
              text: '全部',
              val: ''
            },
            {
              text: '今天',
              val: 'today'
            },
            {
              text: '昨天',
              val: 'yesterday'
            },
            {
              text: '最近7天',
              val: 'lately7'
            },
            {
              text: '最近30天',
              val: 'lately30'
            },
            {
              text: '本月',
              val: 'month'
            },
            {
              text: '本年',
              val: 'year'
            }
          ]
        },
        selectionList: [],
        tabClickIndex: '',
        ids: '',
        id:"",
        tableFromLog: {
          page: 1,
          limit: 10
        },
        tableDataLog: {
          data: [],
          total: 0
        },
        LogLoading: false,
        editDialogVisible: false,
        evaluationStatusList: [{
            value: '',
            label: '全部'
          },
          {
            value: 1,
            label: '已回复'
          },
          {
            value: 0,
            label: '未回复'
          }
        ],
        orderDatalist: null,
        editData: {},
        options: [{
          value: '1',
          label: '审核通过'
        }, {
          value: '2',
          label: '审核失败'
        }],
      }
    },
    mounted() {
      this.getList(1)
    },
    methods: {
      handleReply(id) {
        this.editDialogVisible = true
        this.id=id
      },
      save() {
        highPriceCheckApi(this.id, this.editData).then(res => {
          this.editDialogVisible = false
          this.editData = {}
          this.getList()
        }).catch(err => {
          this.$message.error(err.message)
        })
      },
      handleSelectionChange(val) {
        this.selectionList = val
        const data = []
        this.selectionList.map(item => {
          data.push(item.id)
        })
        this.ids = data.join(',')
      },
      // 选择时间
      selectChange(tab) {
        this.tableFrom.date = tab
        this.timeVal = []
        this.getList(1)
      },
      // 具体日期
      onchangeTime(e) {
        this.timeVal = e
        this.tableFrom.date = e ? this.timeVal.join('-') : ''
        this.getList(1)
      },
      // 把每一行的索引放进row
      tableRowClassName({
        row,
        rowIndex
      }) {
        row.index = rowIndex;
      },
      // 添加明细原因 row 当前行 column 当前列
      tabClick(row) {
        this.tabClickIndex = row.index;
        //   this.tabClickLabel = column.label;
      },
      // 失去焦点初始化
      inputBlur(scope) {
        if (!scope.row.sort || scope.row.sort < 0) scope.row.sort = 0
        reviewsSort(scope.row.reply_id, {
            sort: scope.row.sort
          })
          .then((res) => {
            this.closeEdit();
            //   this.$message.success(res.message);
          })
          .catch((res) => {
            //  this.$message.error(res.message);
          });
      },
      closeEdit() {
        this.tabClickIndex = null;
      },
      // 列表
      getList(num) {
        this.listLoading = true
        this.tableFrom.page = num ? num : this.tableFrom.page;
        highPriceLstApi(this.tableFrom)
          .then(res => {
            this.tableData.data = res.data.list
            this.tableData.total = res.data.count
            this.listLoading = false
          })
          .catch(res => {
            this.$message.error(res.message)
            this.listLoading = false
          })
      },
      pageChange(page) {
        this.tableFrom.page = page
        this.getList('')
      },
      handleSizeChange(val) {
        this.tableFrom.limit = val
        this.getList('')
      }
    }
  }
</script>

<style lang="scss" scoped>
  .selWidth {
    width: 300px;
  }

  table .el-image {
    display: inline-block;
  }

  .el-dropdown-link {
    cursor: pointer;
    color: #409eff;
    font-size: 12px;
  }

  .el-icon-arrow-down {
    font-size: 12px;
  }

  .tabBox_tit {
    width: 60%;
    font-size: 12px !important;
    margin: 0 2px 0 10px;
    letter-spacing: 1px;
    padding: 5px 0;
    box-sizing: border-box;
  }

  .mt20 {
    margin-top: 20px;
  }

  .demo-image__preview {
    position: relative;
  }

  .maxw180 {
    display: inline-block;
    max-width: 180px;
  }
</style>
